[Content Addressable] Bundler Local Cache and Lockfile - #178
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds Bundler/RubyGems support for content-addressable gem artifacts end-to-end, including compact-index v2 test infrastructure, lockfile encoding/parsing, and ensuring local cache resolution works with content-addressed filenames.
Changes:
- Extend specification/name tuple objects to carry
content_address, and update resolution & lockfile serialization/parsing accordingly. - Add Artifice compact-index v2 helpers to model content-addressable gems in specs, including platform metadata injection.
- Add/adjust specs to cover lockfile formatting/parsing and local-cache round-trips for content-addressable gems.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| spec/support/builders.rb | Build helper now supports producing content-addressable gem files (Ruby ABI–scoped). |
| spec/support/artifice/helpers/compact_index.rb | Checksum calculation updated to use spec.full_name gem filenames. |
| spec/support/artifice/helpers/compact_index_v2.rb | New compact-index v2 Artifice helper with content-addressable gem support and metadata injection. |
| spec/support/artifice/helpers/compact_index_cooldown.rb | Removed (superseded by v2 helper). |
| spec/support/artifice/compact_index_v2.rb | New Artifice activation entrypoint for the v2 helper. |
| spec/support/artifice/compact_index_cooldown.rb | Removed (tests now use compact_index_v2). |
| spec/other/ext_spec.rb | Add coverage for Gem::NameTuple#lock_name and Bundler::LazySpecification#to_lock with content addresses. |
| spec/install/gemfile/content_addressable_spec.rb | New integration specs for content-addressable install, caching, and lockfile round-trips. |
| spec/install/cooldown_spec.rb | Switch cooldown tests to use the compact-index v2 Artifice setup. |
| spec/bundler/remote_specification_spec.rb | Rename “platform” to “suffix” in test setup and add content-address expectation coverage. |
| spec/bundler/override_spec.rb | Ensure overrides stubs include content_address. |
| spec/bundler/lockfile_parser_spec.rb | Add parsing coverage for lockfile lines with a trailing content address token. |
| spec/bundler/endpoint_specification_spec.rb | Add coverage for CA suffix handling via platform metadata and remote fetching behavior. |
| lib/rubygems/specification.rb | Include content_address in Specification#name_tuple. |
| lib/rubygems/safe_marshal.rb | Permit Gem::NameTuple to safely marshal/unmarshal @content_address. |
| lib/rubygems/name_tuple.rb | Add content_address field on Gem::NameTuple. |
| lib/bundler/stub_specification.rb | Propagate content_address when building StubSpecifications. |
| lib/bundler/source/rubygems.rb | Preserve content address when swapping remote specs after download. |
| lib/bundler/rubygems_integration.rb | Populate spec content_address from Gem::Package when available. |
| lib/bundler/rubygems_gem_installer.rb | Call RubyGems’ content-address assignment hook when supported. |
| lib/bundler/rubygems_ext.rb | Compatibility shims for older RubyGems plus lock name behavior for content-addressed tuples. |
| lib/bundler/resolver.rb | De-dupe resolved specs including content_address to avoid collapsing distinct CA variants. |
| lib/bundler/remote_specification.rb | Add content_address and include it in full_name when applicable. |
| lib/bundler/match_platform.rb | Prefer compatible content-addressable candidates when available. |
| lib/bundler/lockfile_parser.rb | Parse trailing content-address token on spec lines and propagate into LazySpecification. |
| lib/bundler/lazy_specification.rb | Track content_address, include it in full_name, and emit it in lock output. |
| lib/bundler/fetcher.rb | Treat the 3rd token as a “suffix” and pass through to endpoint/remote specification constructors. |
| lib/bundler/endpoint_specification.rb | Add CA suffix parsing via metadata-provided platform and fetch remote specs using CA suffix when present. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
474c200 to
e884790
Compare
e884790 to
9f26cc0
Compare
9f26cc0 to
b985f74
Compare
b985f74 to
7179457
Compare
| spec = @specs[full_name] | ||
| lock_name = Gem::NameTuple.new(name, version, platform).lock_name | ||
| @specs_by_lock_name ||= @specs.values.to_h {|candidate| [candidate.lock_name, candidate] } | ||
| spec = @specs[full_name] || @specs_by_lock_name[lock_name] |
There was a problem hiding this comment.
This allows us to correctly find the CA gem spec by either the full_name OR the lock_name after the recent naming changes, when storing the checksum.
7179457 to
582815e
Compare
aad98a3 to
0caed62
Compare
582815e to
0f79ede
Compare
jenshenny
left a comment
There was a problem hiding this comment.
Looking nice! I just had a question on the way we're storing the CA and the platform in the lockfile.
I'm curious on why the platform is being stored for the lock name and have CA outside instead of the CA as the lock name and the platform outside. The CA would provide uniqueness and be clear that it's the suffix of the .gem file but I might be missing something.
Yeah I see what you mean. It's just because the regex in I'm happy to be outvoted though if you feel strongly. |
Ah I see! I still feel that switching the CA and the platform make most sense to me because it's consistent throughout the system that the content address is the version token for skinny gems and the platform is the version token for fat ones. Having that discrepancy in the lockfile is a bit confusing to me... It's a bit more work to handle both in |
66e5cca to
97380de
Compare
jenshenny
left a comment
There was a problem hiding this comment.
Approving to unblock! Looks good, just some other minor comments on other backwards compat cases
|
|
||
| def name_tuple | ||
| Gem::NameTuple.new(@name, @version, @platform) | ||
| Gem::NameTuple.new(@name, @version, @platform, content_address: @content_address) |
There was a problem hiding this comment.
I think this is causing jruby to fail, I think we could add something in rubygems_ext to omit the additional arg based on RG version.
There was a problem hiding this comment.
Nice thanks - I've added the shim based on whether initialize accepts content_address or not rather than tieing to a version, thinking this will make it more robust, just in case.
Append platform to content-addressable gems entries in lockfile Support content addressable gems in lockfile and local cache
97380de to
ce7e319
Compare
a7d2ef8
into
feature-branch-ca-changes-rubygems
ruby#9733
TL;DR
This PR updates the bundler install flow for locally cached gems to support content addressable gem naming.
Description
This PR builds on the Bundler remote-install support for content-addressed gems.
It writes the gem’s content address and platform to
Gemfile.lock, then parses those values back intoLazySpecificationduring a subsequent install. This lets Bundler identify the content-addressed.geminvendor/cacheand install it withbundle install --local, without contacting the remote source again.The same content-addressed name is used for the installed gem directory in both remote and local installation paths, ensuring lockfile round-trips produce a consistent on-disk layout.
Tests
Updates made to
lockfile_parser_spec,content_addressable_specandext_specto cover the changes.Tophatting
bundle installfrom the directory that contains your gemfile, using a Ruby version compatible with the content addressable gem.Gemfile.lockcontains a content address:/cache/directory)bundle install --local. Confirm the content addressable gem installs correctly still and that it uses the correct content addressable name.I've performed this tophat locally and it's all looking good! ✅